package k2_oop.p2_inheritAndPolymorphic.demo05;

/**
 * 再定义一个小汽车类Car，继承Auto，并添加空调、CD等成员变量，覆盖加速，减速的方法
 */
public class Car extends Auto{

    //新增是否开空调
    private boolean isOpenAirConditioner;
    //是否有CD
    private boolean hasCD;

    public Car(int tyreCount, String color, double weight, int speed, boolean isOpenAirConditioner, boolean hasCD) {
        super(tyreCount, color, weight, speed);
        this.isOpenAirConditioner = isOpenAirConditioner;
        this.hasCD = hasCD;
    }

    @Override
    public void speedUp(int speed) {
        this.setSpeed(this.getSpeed()+speed);
        System.out.println("小汽车加速完毕");
    }

    @Override
    public void speedDown(int speed) {
        if(this.getSpeed()>=speed){
            this.setSpeed(this.getSpeed()-speed);
        }else{
            this.setSpeed(0);
        }
        System.out.println("小汽车减速完毕");
    }

    public boolean isOpenAirConditioner() {
        return isOpenAirConditioner;
    }

    public void setOpenAirConditioner(boolean openAirConditioner) {
        isOpenAirConditioner = openAirConditioner;
    }

    public boolean isHasCD() {
        return hasCD;
    }

    public void setHasCD(boolean hasCD) {
        this.hasCD = hasCD;
    }
}
